package com.ruoyi.web.controller.wbgame;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wbgame.domain.WbGame;
import com.ruoyi.wbgame.service.IWbGameService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 游戏Controller
 * 
 * @author guguofu
 * @date 2021-04-16
 */
@Controller
@RequestMapping("/wbgame/game")
public class WbGameController extends BaseController
{
    private String prefix = "wbgame/game";

    @Autowired
    private IWbGameService wbGameService;

    @RequiresPermissions("wbgame:game:view")
    @GetMapping()
    public String game()
    {
        return prefix + "/game";
    }

    /**
     * 查询游戏列表
     */
    @RequiresPermissions("wbgame:game:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WbGame wbGame)
    {
        startPage();
        List<WbGame> list = wbGameService.selectWbGameList(wbGame);
        return getDataTable(list);
    }

    /**
     * 导出游戏列表
     */
    @RequiresPermissions("wbgame:game:export")
    @Log(title = "游戏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WbGame wbGame)
    {
        List<WbGame> list = wbGameService.selectWbGameList(wbGame);
        ExcelUtil<WbGame> util = new ExcelUtil<WbGame>(WbGame.class);
        return util.exportExcel(list, "game");
    }

    /**
     * 新增游戏
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存游戏
     */
    @RequiresPermissions("wbgame:game:add")
    @Log(title = "游戏", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WbGame wbGame)
    {
        return toAjax(wbGameService.insertWbGame(wbGame));
    }

    /**
     * 修改游戏
     */
    @GetMapping("/edit/{gameId}")
    public String edit(@PathVariable("gameId") Long gameId, ModelMap mmap)
    {
        WbGame wbGame = wbGameService.selectWbGameById(gameId);
        mmap.put("wbGame", wbGame);
        return prefix + "/edit";
    }

    /**
     * 修改保存游戏
     */
    @RequiresPermissions("wbgame:game:edit")
    @Log(title = "游戏", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WbGame wbGame)
    {
        return toAjax(wbGameService.updateWbGame(wbGame));
    }

    /**
     * 删除游戏
     */
    @RequiresPermissions("wbgame:game:remove")
    @Log(title = "游戏", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wbGameService.deleteWbGameByIds(ids));
    }
}
